<%@page import="com.realjinge.api.util.JsSignUtil"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
	+ request.getServerName() + ":" + request.getServerPort()
	+ path + "/";
	// 动态获取url地址
	// String url = request.getScheme()+"://"+ request.getServerName()+request.getRequestURI()+"?"+request.getQueryString();
	String url = request.getScheme()+"://"+ request.getServerName()+request.getRequestURI();
	// System.out.println(url);
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>微信扫一扫</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<meta name="viewport"
	content="width=device-width,minimum-scale=1.0, maximum-scale=2.0" />
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script type="text/javascript">
	
	// < %Map<String, String> ret = new HashMap<String, String>();
	// ret = JsSignUtil.sign(url);% > 
			
    wx.config({  
        debug: false,  
        appId: '${ret.appId }',  
        timestamp:'${ret.timestamp }',  
        nonceStr:'${ret.nonceStr }',  
        signature:'${ret.signature }',
		jsApiList : [ 'checkJsApi', 'scanQRCode' ]
	});//end_config  

	wx.ready(function() {

		wx.checkJsApi({
			jsApiList : [ 'scanQRCode' ],
			success : function(res) {
				// alert("成功了：" + res.errMsg);
			}
		});

		//扫描二维码  
		wx.scanQRCode({
			needResult : 0, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，  
			scanType : [ "qrCode", "barCode" ], // 可以指定扫二维码还是一维码，默认二者都有  
			success : function(res) {
				var result = res.resultStr; // 当needResult 为 1 时，扫码返回的结果  
				document.getElementById("wm_id").value = result;//将扫描的结果赋予到jsp对应值上  
				alert("扫描成功！扫描码=" + result);
			}

		});

	});//end_ready

	wx.error(function(res) {
		alert("出错了：" + res.errMsg);
	});//end_error
</script>
</head>

<body style="background: gray;">
	<hr>
	<h1 style="text-align: center;">微信扫一扫接口测试</h1>
	<hr>
	<br />
	<div style="text-align: center;">
		<h1>
			<input type="text" id="wm_id" name="wm_id">
		</h1>
	</div>
	<br />
	<div style="text-align: center;vertical-align: middle;">
		<button id="scanQRCode">
			<h2>微信扫一扫</h2>
		</button>
	</div>
</body>
</html>